﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class aspnet_admin_bock_CX_Collert_Class_Edit : System.Web.UI.Page
{
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public Tong.TongUse TextData = new Tong.TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = Tong.TongUse.SysPath;

    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    DataTable NewDt = new DataTable();

    public string str = "";

    /// <summary>
    /// 采集内容列表
    /// </summary>
    public string StrList = "";

    /// <summary>
    /// 链接到内容页
    /// </summary>
    public String StrLink = "";

    /// <summary>
    /// 内容页标题
    /// </summary>
    public string StrTitle = "";

    /// <summary>
    /// 内容显示
    /// </summary>
    public String StrContont = "";
    /// <summary>
    /// 这个分类的ID
    /// </summary>
    string Rid = "";

    /// <summary>
    /// 站点通用方法类
    /// </summary>
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {
        //帮字数据
        if (!IsPostBack)
        {
            BindData();

        }
        
        Authors.Attributes.Add("onchange", "document.getElementById('" + CX_Collect_Class_Creater.ClientID + "').value=this.value;");

        CX_Collect_Class_List.Attributes.Add("onclick", "storeCaret(this);");
        CX_Collect_Class_List.Attributes.Add("onselect", "storeCaret(this);");
        CX_Collect_Class_List.Attributes.Add("onkeyup", " storeCaret(this);");

        CX_Collect_Class_Link.Attributes.Add("onclick", "storeCaret(this);");
        CX_Collect_Class_Link.Attributes.Add("onselect", "storeCaret(this);");
        CX_Collect_Class_Link.Attributes.Add("onkeyup", " storeCaret(this);");


        CX_Collect_Class_Title.Attributes.Add("onclick", "storeCaret(this);");
        CX_Collect_Class_Title.Attributes.Add("onselect", "storeCaret(this);");
        CX_Collect_Class_Title.Attributes.Add("onkeyup", " storeCaret(this);");


        CX_Collect_Class_Contont.Attributes.Add("onclick", "storeCaret(this);");
        CX_Collect_Class_Contont.Attributes.Add("onselect", "storeCaret(this);");
        CX_Collect_Class_Contont.Attributes.Add("onkeyup", " storeCaret(this);");


        StrList = CX_Collect_Class_List.ClientID;
        StrLink = CX_Collect_Class_Link.ClientID;
        StrTitle = CX_Collect_Class_Title.ClientID;
        StrContont = CX_Collect_Class_Contont.ClientID;


    }



    /// <summary>
    /// 保存数据
    /// </summary>
    void PageSave()
    {
        string sql = "";
        string CX_Column_id = "";
        //看看是不是有选中 CX_NEWS_Class_id
        try
        {
            CX_Column_id = Request.Form["CX_Column_id"].Trim().Replace("'", "").Replace("\"", "");
        }
        catch
        {
            TextData.Err("程序不能完成你的添加新闻操作<br/>您没有选择所要添加新闻的分类");
        }

        try
        {
            int.Parse(CX_Column_id.Trim());
            Rid = Request.QueryString["id"].ToString().Trim();
        }
        catch
        {
            tt.Text = "参数错误,不能进行更新操作";
            Response.End();
        }
        if (CX_Collect_Class_Name.Text.Trim() != "" && CX_Collect_Class_Itemplitate.Text.Trim() != "")
        {
            //是不是远程图片
            string Collect_Parame = "false";
            //看看HTML
            string Collect_HTML = "false";

            //样式
            string Collect_STYLE = "false";

            //DIV
            string Collect_Div = "false";

            //Alink
            string Collect_A = "false";

            //Class 
            string Collect_CLASS = "false";

            //是不是要 font
            string Collect_Font = "false";

            //SPAN
            string Collect_SPAN = "false";

            //Iframe
            string Collect_IFRAME = "false";

            //script
            string Collect_SCRIPT = "false";

            string Collect_OBJECT = "false";


            if (CX_Collect_Class_Filtrate_OBJECT.Checked == true)
            {

                Collect_OBJECT = "true";
            }


            if (CX_Collect_Class_Filtrate_SCRIPT.Checked == true)
            {

                Collect_SCRIPT = "true";
            }

            if (CX_Collect_Class_Filtrate_IFRAME.Checked == true)
            {
                Collect_IFRAME = "true";
            }

            if (CX_Collect_Class_Filtrate_SPAN.Checked == true)
            {
                Collect_SPAN = "true";
            }

            if (CX_Collect_Class_Filtrate_FONT.Checked == true)
            {
                Collect_Font = "true";
            }

            if (CX_Collect_Class_Filtrate_CLASS.Checked == true)
            {
                Collect_CLASS = "true";
            }

            if (CX_Collect_Class_Filtrate_A.Checked == true)
            {
                Collect_A = "true";
            }

            if (CX_Collect_Class_Filtrate_DIV.Checked == true)
            {
                Collect_Div = "true";
            }


            if (CX_Collect_Class_Filtrate_STYLE.Checked == true)
            {
                Collect_STYLE = "true";
            }

            if (CX_Collect_Class_Parame.Checked == true)
            {

                Collect_Parame = "true";

            }

            if (CX_Collect_Class_Filtrate_HTML.Checked == true)
            {
                Collect_HTML = "true";
            }


            //sql += "@CX_Collect_Class_Name=" + CX_Collect_Class_Name.Text.Trim() + "," +
            //        "@CX_Collect_Class_Page=" + CX_Collect_Class_Page.Text.Trim() + "," +
            //        "@CX_Column_id=" + CX_Column_id.SelectedValue.Trim() + "," +
            //        "@CX_Collect_Class_CrtFileName=" + CX_Collect_Class_CrtFileName.Text.Trim() + "," +
            //        "@CX_Collect_Class_CharSet=" + CX_Collect_Class_CharSet.Value.Trim() + "," +
            //        "@CX_Collect_Class_Parame=" + Collect_Parame + "," +//是不是远程图片
            //        "@CX_Collect_Class_Itemplitate=" + CX_Collect_Class_Itemplitate.Text.Trim() + "," +
            //        "@CX_Collect_Class_Itemplitate_Parame=" + CX_Collect_Class_Itemplitate_Parame.Text.Trim() + "," +
            //        "@CX_Collect_Class_UpFile=" + CX_Collect_Class_UpFile.Text.Trim() + "," +
            //        "@CX_Collect_Class_Creater=" + CX_Collect_Class_Creater.Text.Trim() + "," +
            //        "@CX_Collect_Class_Filtrate_HTML=" + Collect_HTML + "," +
            //        "@CX_Collect_Class_Filtrate_STYLE=" + Collect_STYLE + "," +
            //        "@CX_Collect_Class_Filtrate_DIV=" + Collect_Div + "," +
            //        "@CX_Collect_Class_Filtrate_A=" + Collect_A + "," +
            //        "@CX_Collect_Class_Filtrate_CLASS=" + Collect_CLASS + "," +
            //        "@CX_Collect_Class_Filtrate_FONT=" + Collect_Font + "," +
            //        "@CX_Collect_Class_Filtrate_SPAN=" + Collect_SPAN + "," +
            //        "@CX_Collect_Class_Filtrate_IFRAME=" + Collect_IFRAME + "," +
            //        "@CX_Collect_Class_Filtrate_SCRIPT=" + Collect_SCRIPT + "," +
            //        "@CX_Collect_Class_Filtrate_OBJECT=" + Collect_OBJECT + "," +
            //        "@CX_Collect_Class_List=" + CX_Collect_Class_List.Text.Trim() + "," +
            //        "@CX_Collect_Class_Link=" + CX_Collect_Class_Link.Text.Trim() + "," +
            //        "@CX_Collect_Class_Title=" + CX_Collect_Class_Title.Text.Trim() + "," +
            //        "@CX_Collect_Class_Contont=" + CX_Collect_Class_Contont.Text.Trim() + "," +
            //        "@id= " + Rid + "";
                    
            

            //得到所有字段
            if (int.Parse(Rid).ToString()!="")
            {

                sql = "update [CX_Collect_Class] Set  ";
                sql += "CX_Collect_Class_Name='" + CX_Collect_Class_Name.Text.Trim().Replace("'","") + "'," +
                    "CX_Collect_Class_Page='" + CX_Collect_Class_Page.Text.Trim().Replace("'", "") + "'," +
                    "CX_Column_id=" + CX_Column_id.Trim().Replace("'", "") + "," +
                    "CX_Collect_Class_CrtFileName='" + CX_Collect_Class_CrtFileName.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_CharSet='" + CX_Collect_Class_CharSet.Value.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Parame='" + Collect_Parame + "'," +//是不是远程图片
                    "CX_Collect_Class_Itemplitate='" + CX_Collect_Class_Itemplitate.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Itemplitate_Parame='" + CX_Collect_Class_Itemplitate_Parame.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_UpFile='" + CX_Collect_Class_UpFile.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Creater='" + CX_Collect_Class_Creater.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Filtrate_HTML='" + Collect_HTML + "'," +
                    "CX_Collect_Class_Filtrate_STYLE='" + Collect_STYLE + "'," +
                    "CX_Collect_Class_Filtrate_DIV='" + Collect_Div + "'," +
                    "CX_Collect_Class_Filtrate_A='" + Collect_A + "'," +
                    "CX_Collect_Class_Filtrate_CLASS='" + Collect_CLASS + "'," +
                    "CX_Collect_Class_Filtrate_FONT='" + Collect_Font + "'," +
                    "CX_Collect_Class_Filtrate_SPAN='" + Collect_SPAN + "'," +
                    "CX_Collect_Class_Filtrate_IFRAME='" + Collect_IFRAME + "'," +
                    "CX_Collect_Class_Filtrate_SCRIPT='" + Collect_SCRIPT + "'," +
                    "CX_Collect_Class_Filtrate_OBJECT='" + Collect_OBJECT + "'," +
                    "CX_Collect_Class_List='" + CX_Collect_Class_List.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Link='" + CX_Collect_Class_Link.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Title='" + CX_Collect_Class_Title.Text.Trim().Replace("'", "") + "'," +
                    "CX_Collect_Class_Contont='" + CX_Collect_Class_Contont.Text.Trim().Replace("'", "") + "'";
                sql+= "  where CX_Collect_Class_id="+Rid;

                TextData.SqlDataSave(sql);
                tt.Text = "修改采集设定 " + CX_Collect_Class_Name.Text.Trim() + " 成功";
                BindData();
                //CX_Collect_Class_Name.Text = "";
               // CX_Collect_Class_CrtFileName.Text = "";
            }
            else
            {
                tt.Text = "可能有同名设定项,或出现未知错误 ";
            }


            //BindData();
        }
        else
        {
            tt.Text = "输入的信息内容不正确";
        }
    }

    /// <summary>
    /// ajax模式
    /// </summary>
    /// <param name="Sid"></param>
    /// <returns></returns>
    public String Chenge(string Sid)
    {

        if (Sid != "")
        {
            MyDt = TextData.SqlataSet("select top 1 * from [CX_News_Class] where CX_News_Class_id = " + Sid).Tables[0];
            //CX_Collect_Class_Itemplitate.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Address"].ToString();
            //CX_Collect_Class_Itemplitate_Parame.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Parame"].ToString();
            // MyDt.Clear();
            MyDt.Dispose();
            str = "    var ajax=new AJAXRequest();ajax.post('CX_Coolert_News_Class.ashx?id='+Id,'t=" + CX_Collect_Class_Itemplitate.ClientID + "&p=" + CX_Collect_Class_Itemplitate_Parame.ClientID + "',function(obj) { eval(obj.responseText); });";
        }
        return str;
    }


    void BindData()
    {

        try
        {
            Rid = Request.QueryString["id"].ToString().Trim();

            DataTable CollectEditTable = new DataTable();

            CollectEditTable = TextData.SqlataSet("select * from [CX_Collect_Class] where CX_Collect_Class_id="+Rid).Tables[0];

            //帮定各个字段的值
            				CX_Collect_Class_Name.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Name"].ToString();

                            CX_Collect_Class_Page.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Page"].ToString(); 
							
							CX_Collect_Class_CrtFileName.Text = CollectEditTable.Rows[0]["CX_Collect_Class_CrtFileName"].ToString();  
							CX_Collect_Class_CharSet.Value = CollectEditTable.Rows[0]["CX_Collect_Class_CharSet"].ToString();
                            CX_Collect_Class_Parame.Checked = Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Parame"].ToString()); 
  
							CX_Collect_Class_Filtrate_HTML.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_HTML"].ToString()); 
							CX_Collect_Class_Filtrate_STYLE.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_STYLE"].ToString());
  
							CX_Collect_Class_Filtrate_DIV.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_DIV"].ToString());  
							CX_Collect_Class_Filtrate_A.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_A"].ToString());   

							CX_Collect_Class_Filtrate_CLASS.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_CLASS"].ToString());  
							CX_Collect_Class_Filtrate_FONT.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_FONT"].ToString());  

							CX_Collect_Class_Filtrate_SPAN.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_SPAN"].ToString());  
							CX_Collect_Class_Filtrate_IFRAME.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_IFRAME"].ToString());  
							CX_Collect_Class_Filtrate_SCRIPT.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_SCRIPT"].ToString());  
							CX_Collect_Class_Filtrate_OBJECT.Checked=Convert.ToBoolean(CollectEditTable.Rows[0]["CX_Collect_Class_Filtrate_OBJECT"].ToString());

                            CX_Collect_Class_Itemplitate.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Itemplitate"].ToString();
                            CX_Collect_Class_Itemplitate_Parame.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Itemplitate_Parame"].ToString();
                            CX_Collect_Class_UpFile.Text = CollectEditTable.Rows[0]["CX_Collect_Class_UpFile"].ToString();
                            CX_Collect_Class_Creater.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Creater"].ToString();
                            CX_Collect_Class_List.Text = CollectEditTable.Rows[0]["CX_Collect_Class_List"].ToString();
                            CX_Collect_Class_Link.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Link"].ToString();
                            CX_Collect_Class_Title.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Title"].ToString();
                            CX_Collect_Class_Contont.Text = CollectEditTable.Rows[0]["CX_Collect_Class_Contont"].ToString();
                            

            
                            //如果新闻分类为空
                            try
                            {
                                ////使用ajaxpro动态改变值   CXgetVlaues
                                ColumnID.Text = "<select id=\"CX_Column_id\"  onchange=\"CXgetVlaues(this.value);\" name=\"CX_Column_id\">\r\n" + TextThisSite.selectMueuOption(0, CollectEditTable.Rows[0]["CX_Column_id"].ToString()) + "</select>";


                            }
                            catch
                            {
                                ColumnID.Text =  "<select id=\"CX_Column_id\" onchange=\"CXgetVlaues(this.value);\"  name=\"CX_Column_id\">\r\n" + TextThisSite.selectMueuOption(0, "aa") + "</select>";

                            }
            Chenge(CollectEditTable.Rows[0]["CX_Column_id"].ToString());

            CollectEditTable.Clear();
            CollectEditTable.Dispose();
        }
        catch(Exception ex)
        {
            tt.Text = ex.Message;
            //MyDt.Clear();
            MyDt.Dispose();
            //NewDt.Clear();
            NewDt.Dispose();
            System.GC.Collect();
        }
        

        //MyDt.Clear();
        MyDt.Dispose();
        //NewDt.Clear();
        NewDt.Dispose();
    }


    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        PageSave();
    }

}
